package kr.hkit.coffeemgn.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import kr.hkit.framework.dao.CloseDAOUtil;



public class CoffeeDAO {
	private Connection con;
	

	public CoffeeDAO() {
		super();
	}

	public CoffeeDAO(Connection con) {
		this.con = con;
	}

	public void setCon(Connection con) {
		this.con = con;
	}
	
	public String selectNameByCode(String code) throws Exception{
		String sql = "select name from product_info where code = ?";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			pstmt = con.prepareStatement(sql);
			pstmt.setString(1, code);
			rs = pstmt.executeQuery();
			if (rs.next()){
				return rs.getString("name");
			}else{
				throw new Exception("해당 제품이 존재하지 않음");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			CloseDAOUtil.close(pstmt);
		}
		return null;
	}
}
